var ctx = window.daijia.ctx;
var lng = window.daijia.lng;
var lat = window.daijia.lat;
var jgpt = window.jgpt;
var map = null; //地图对象
var offset = 0;
var limit = 20;
var pagingLimit = 20;//显示分页时的条数
var currentTotalElements = 0;//当前显示总条数
var pageLoading = true;//是否能滚动加载
var hasShowPages = false;//是否已显示分页
var firstLoadPages = true;//分页初始化时 不自动加载
//筛选条件,
var search_orderNumber = null;
var search_treatment = null;
var search_clientPhone = null;
var search_driverPhone = null;
var search_companyName = null;
var search_createOrderName = null;
var search_startTime = null;
var search_endTime = null;
var search_startFinishTime = null;
var search_endFinishTime = null;
var search_orderType = [];
var search_status = [];
var allmap2 = null;//专车地图对象
var map2 = null;
var driving = null;
var zj_map = null;
var zj_driving = null;
var distance = null;
var timeStr = null;
var start = new Array();
var end = new Array();


$(document).ready(function () {
    $(document).on("click", ".zhuijia", function () {
        var id = $(this).attr("orderId");
        window.open(ctx + "/zhuanche/addmore/" + id, "_blank", "height=850,width=1220,scrollbars=yes,resizable=yes,alwaysRaised=yes,toolbar=no");
    });
    window.setInterval(function () {
        initdata(false);
    }, 1000 * 60);
});

//添加订单结束
$("#startTime1").datetimepicker({
    format: 'yyyy-mm-dd HH:ii',
    language: 'zh-CN',
    minView: 'hour',
    pickDate: true,
    pickTime: false,
    inputMask: false,
    autoclose: true
});
$('#serverTime').change(function () {
    if (!(/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)\s+([01][0-9]|2[0-3]):[0-5][0-9]$/.test($('#serverTime').val()))) {
        $.scojs_message("请输入正确的时间格式,如:2015-12-30 12:30", $.scojs_message.TYPE_ERROR);
        $('#serverTime').val('');
    }
});

$("#startTime").datetimepicker({
    format: "yyyy-mm-dd HH:ii",
    language: 'zh-CN',
    showMeridian: true,
    autoclose: true,
    todayBtn: true
});
$("#endTime").datetimepicker({
    format: "yyyy-mm-dd HH:ii",
    language: 'zh-CN',
    showMeridian: true,
    autoclose: true,
    todayBtn: true
});
$("#startFinishTime").datetimepicker({
    format: "yyyy-mm-dd HH:ii",
    language: 'zh-CN',
    showMeridian: true,
    autoclose: true,
    todayBtn: true
});
$("#endFinishTime").datetimepicker({
    format: "yyyy-mm-dd HH:ii",
    language: 'zh-CN',
    showMeridian: true,
    autoclose: true,
    todayBtn: true
});

$("#zj_startTime1").datetimepicker({
    format: 'yyyy-mm-dd HH:ii',
    language: 'zh-CN',
    minView: 'hour',
    pickDate: true,
    pickTime: false,
    inputMask: false,
    autoclose: true
});
$('#zj_serverTime').change(function () {
    if (!(/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)\s+([01][0-9]|2[0-3]):[0-5][0-9]$/.test($('#zj_serverTime').val()))) {
        $.scojs_message("请输入正确的时间格式,如:2015-12-30 12:30", $.scojs_message.TYPE_ERROR);
        $('#zj_serverTime').val('');
    }
});

initdata(false);

//高级搜索
$(".query-jiant").click(function () {
    var src = $("#jiant").attr("src");
    if (src.indexOf("jiant2") >= 0) {
        $("#jiant").attr("src", ctx + "/assets/img/jiant.png");
        $(".choose").show(300);
    } else {
        $("#jiant").attr("src", ctx + "/assets/img/jiant2.png");
        $(".choose").hide(300);
    }
});
//销单
$(document).on("click", ".cancle", function () {
    $("#dialog_cancel_id").val($(this).attr('orderId'));
    $("#ok_modal_cancel").attr("disabled", false);
    $('#dialog_cancel').modal();
});
$("#close_modal_cancel").click(function () {
    $('#dialog_cancel').modal("hide");
});
$("#ok_modal_cancel").click(function () {
    if ($("input[name=cancel_reason]:checked").length == 0) {
        $.scojs_message("请选择销单原因", $.scojs_message.TYPE_ERROR);
        return false;
    }
    if ($("input[name=cancel_reason]:checked").val() == "other" && $("#dialog_cancel_content").val().length == 0) {
        $.scojs_message("请输入销单原因", $.scojs_message.TYPE_ERROR);
        return false;
    }
    var content = "";
    if ($("input[name=cancel_reason]:checked").val() == "other") {
        content = $("#dialog_cancel_content").val();
    } else {
        content = $("input[name=cancel_reason]:checked").val();
    }
    $(this).attr("disabled", true);
    $.post($(this).attr("action"), {'id': $("#dialog_cancel_id").val(), 'cause': content}, function (data) {
        if (data.success) {
            $.scojs_message(data.message, $.scojs_message.TYPE_OK);
            setTimeout(function () {
                window.location.reload(true);
            }, 1000);
        } else {
            $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
        }
    }, 'json');
});
//备注
$(document).on("click", '.modifyCash', function () {
    var orderId = $(this).attr('orderId');
    var orderNo = $(this).attr('orderNo');
    var orderMemo = $(this).attr('orderMemo');
    $('#orderId').val(orderId);
    $('#orderNo').html(orderNo);
    $('#oldmemo').val(orderMemo);
    $('#dialog_modifyCash').modal();
});
$("#save").click(function () {
    $('#dialog_modifyCash').modal("hide");
    $.post(ctx + '/zhuanche/remark', {'id': $('#orderId').val(), 'memo': $('#memo').val()}, function (data) {
        if (data.success) {
            $.scojs_message(data.message, $.scojs_message.TYPE_OK);
            setTimeout(function () {
                window.location.reload(true);
            }, 1000);
        } else {
            $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
            setTimeout(function () {
                window.location.reload(true);
            }, 1000);
        }
    }, 'json');
});
$("#close_modal_memo").click(function () {
    $('#dialog_modifyCash').modal("hide");
});
//收回
$(document).on("click", ".callback", function () {
    $('#orderId3').val($(this).attr('orderId'));
    $('#orderNo3').html($(this).attr('orderNo'));
    $('#dialog_callback').modal();
});
$("#callback").click(function () {
    var cause = $("#cause3").val().trim();
    if (cause == null || cause == "") {
        $.scojs_message("收回原因不能为空", $.scojs_message.TYPE_ERROR);
        return;
    }
    var params = {id: $("#orderId3").val(), cause: $("#cause3").val()}
    $.post(ctx + '/zhuanche/callback', params, function (object) {
        if (object.success) {
            $('#dialog_callback').modal("hide");
            $.scojs_message("收回成功", $.scojs_message.TYPE_OK);
            setTimeout(function () {
                window.location.reload(true);
            }, 1000);
        } else {
            $.scojs_message(object.message, $.scojs_message.TYPE_ERROR);
        }
    });
});
$("#close_modal_callback").click(function () {
    $('#dialog_callback').modal("hide");
});
//专车订单派单
var startLng;
var startLat;
var clientName;
var clientPhone;
var fromPlace;
var paidanCarType;
$(document).on("click", ".zhuan_paidan", function () {
    startLng = $(this).attr("startLng");
    startLat = $(this).attr("startLat");
    clientName = $(this).attr("clientName");
    clientPhone = $(this).attr("clientPhone");
    fromPlace = $(this).attr("fromPlace");
    paidanCarType = $(this).attr("paidanCarType");
    $("#paidanOrderId").val($(this).attr("orderId"));
    $("#paidanClientName").html("");
    $("#paidanClientPhone").html("");
    $("#paidanFromPlace").html("");
    $("#paidanCarType").html("");
    $("#dialog_paidan").modal();
});

$('#dialog_paidan').on('shown.bs.modal', function () {
    $("#paidanOrderLng").val(startLng);
    $("#paidanOrderLat").val(startLat);

    showClientMaker(startLng, startLat);
    getDrivers(startLng, startLat);

    $("#paidanClientName").html(clientName);
    $("#paidanClientPhone").html(clientPhone);
    $("#paidanFromPlace").html(fromPlace);
    $("#paidanCarType").html(paidanCarType);
});
$('#distance').change(function () {
    showClientMaker($("#paidanOrderLng").val(), $("#paidanOrderLat").val());
    getDrivers($("#paidanOrderLng").val(), $("#paidanOrderLat").val());
});
$(document).on("click", ".paigeita", function () {
    var driverId = $(this).attr("data-id");
    if (window.confirm('确认要派单给该服务人员吗？')) {
        $.post(ctx + '/zhuanche/paidan', {'driverId': driverId, 'orderId': $("#paidanOrderId").val()}, function (data) {
            if (data.success) {
                $.scojs_message("派单成功", $.scojs_message.TYPE_OK);
                $("#dialog_paidan").modal("hide");
                initdata(false);
            } else {
                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
            }
        });
    }
});


//查询
$("#searchButton").click(function () {
    if ($("input[name=treatment]").is(':checked')) {
        search_treatment = "true";
    } else {
        search_treatment = "false";
    }
    var DATE_FORMAT = /^[0-9]{4}-[0-1]{1}[0-9]{1}-[0-3]{1}[0-9]{1} [0-2]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/;
    if ($("#startTime").val() != "") {
        if (!DATE_FORMAT.test($("#startTime").val())) {
            $.scojs_message("您输入的开始日期格式有误，正确格式如：2016-06-13 12:45", $.scojs_message.TYPE_ERROR);
            return false;
        }
    }

    if ($("#endTime").val() != "") {
        if (!DATE_FORMAT.test($("#endTime").val())) {
            $.scojs_message("您输入的结束日期格式有误，正确格式如：2016-06-13 12:45", $.scojs_message.TYPE_ERROR);
            return false;
        }
    }

    if ($("#startTime").val() != "" && $("#endTime").val() != "") {
        if ($("#startTime").val() > $("#endTime").val()) {
            $.scojs_message("启始日期不能大于结束日期", $.scojs_message.TYPE_ERROR);
            return false;
        }
    }
    if ($("#startFinishTime").val() != "") {
        if (!DATE_FORMAT.test($("#startFinishTime").val())) {
            $.scojs_message("您输入的日期格式有误，正确格式如：2016-06-13 12:45", $.scojs_message.TYPE_ERROR);
            return false;
        }
    }

    if ($("#endFinishTime").val() != "") {
        if (!DATE_FORMAT.test($("#endFinishTime").val())) {
            $.scojs_message("您输入的日期格式有误，正确格式如：2016-06-13 12:45", $.scojs_message.TYPE_ERROR);
            return false;
        }
    }

    if ($("#startFinishTime").val() != "" && $("#endFinishTime").val() != "") {
        if ($("#startFinishTime").val() > $("#endFinishTime").val()) {
            $.scojs_message("启始日期不能大于结束日期", $.scojs_message.TYPE_ERROR);
            return false;
        }
    }

    search_orderNumber = $("#orderNumber").val();
    search_clientPhone = $("#clientPhone").val();
    search_driverPhone = $("#driverPhone").val();
    search_companyName = $("#companyName").val();
    search_createOrderName = $("#createOrderName").val();
    search_startTime = $("#startTime").val();
    search_endTime = $("#endTime").val();
    search_startFinishTime = $("#startFinishTime").val();
    search_endFinishTime = $("#endFinishTime").val();

    var orderTypeArr = [];
    $("input[name=orderType]:checked").each(function (index, element) {
        orderTypeArr.push($(element).val());
    });
    if (null != orderTypeArr && orderTypeArr.length > 0) {
        search_orderType = orderTypeArr.join(",");
    } else {
        search_orderType = [];
    }

    var statusArr = [];
    $("input[name=status]:checked").each(function (index, element) {
        statusArr.push($(element).val());
    });
    if (null != statusArr && statusArr.length > 0) {
        search_status = statusArr.join(",");
    } else {
        search_status = [];
    }
    offset = 0;
    initdata(false);
});

$(document).on("keydown", "body", function () {
    if (window.event.keyCode == 13) {
        $("#searchButton").click();
    }
});

//开始导出
var onExporting = false;
$("#export_button").click(function () {
    $('#dialog_export').modal();
    if (!onExporting) {
        onExporting = true;
        $.get(
            ctx + '/zhuanche/exportOrder',
            {
                'orderNumber': $("#orderNumber").val(),
                'clientPhone': $("#clientPhone").val(),
                'driverPhone': $("#driverPhone").val(),
                'createOrderName': $("#createOrderName").val(),
                'companyName': $("#companyName").val(),
                'orderType': search_orderType,
                'status': search_status,
                'startTime': $("#startTime").val(),
                'endTime': $("#endTime").val()
            },
            function (result) {
                onExporting = false;
                $("#export_process .progress-bar").css("width", "100%");
                $("#export_process .progress-bar span").html("100%已完成");
                window.location = ctx + "/" + result;
            }
        );

        $("#export_process").show();
        $("#export_process .progress-bar").css("width", "1%");
        $("#export_process .progress-bar span").html("0%已完成");
        exportProcess();
    }
});

function exportProcess() {
    $.get(ctx + '/zhuanche/exportOrderProcess', {}, function (data) {
        if (null != data && data != "") {
            $("#export_process .progress-bar").css("width", parseFloat(data) * 100 + "%");
            $("#export_process .progress-bar span").html((parseFloat(data) * 100).toFixed(1) + "%已完成");
        }
    });
}

$(document).ajaxSuccess(function (event, xhr, settings) {
    if (settings.url.indexOf("exportOrderProcess") != -1) {
        setTimeout(function () {
            exportProcess();
        }, 2000);//2s
    }
});


//完工
$(document).on("click", ".wangong", function () {
    window.open(ctx + '/zhuanche/complete/' + $(this).attr("orderId"), '_blank', 'height=500,width=900,scrollbars=yes,resizable=yes,alwaysRaised=yes,toolbar=no');
});


/**
 * 订单补传
 */
$(document).on("click", ".ddbc", function () {
    var id = $(this).attr("data-id");
    if (window.confirm('确认要补传该订单数据吗？')) {
        $.post(ctx + '/zhuanche/ddbc', {'id': id}, function (data) {
            if (data.success) {
                $.scojs_message("订单补传成功", $.scojs_message.TYPE_OK);
            }
        });
    }
});

function initdata(isappend) {
    $.ajax({
        url: ctx + '/zhuanche/orderlistData',
        type: 'GET',
        async: false,
        dataType: 'json',
        data: {
            "treatment": search_treatment,
            "orderNumber": search_orderNumber,
            "clientPhone": search_clientPhone,
            "driverPhone": search_driverPhone,
            "companyName": search_companyName,
            "createOrderName": search_createOrderName,
            "startTime": search_startTime,
            "endTime": search_endTime,
            "startFinishTime": search_startFinishTime,
            "endFinishTime": search_endFinishTime,
            "orderType": search_orderType,
            "status": search_status,
            "pager.offset": offset,
            "limit": limit,
        },
        success: function (result) {
            var newcontent = '';
            var totalElements = result.totalElements;
            $("#NoData").text("");

            if (totalElements > 0) {
                $(result.content).each(function (index, data) {
                    var mainButton = "";
                    var selectButton = "";
                    var stauts = "";
                    var ddbcString = "";
                    if (jgpt) {
                        ddbcString = "<li><a href='javascript:;' data-id='" + data.id + "' class='btn-link ddbc'>补传</a></li>"
                    }

                    if (data.status == 0) {
                        if (hasPermission_paidan) {
                            mainButton = "<a href='#' orderId='" + data.id + "' fromPlace='" + data.startAddress + "' paidanCarType='" + data.carTypeName + "' startLat='" + data.startLat
                                + "' startLng='" + data.startLng + "' clientName='" + data.passengerName + "' clientPhone='" + data.passengerPhone
                                + "' class='btn btn-primary btn-xs zhuan_paidan'>派单</a>";

                            selectButton += "<li><a href='" + ctx + "/zhuanche/detail/" + data.id + "' class='btn-link'>查看</a></li>";
                        } else {
                            mainButton = "<a href='" + ctx + "/zhuanche/detail/" + data.id + "' class='btn btn-primary btn-xs'>查看</a>";
                        }

                        status = "<span class='btn btn-xindan btn-xs'>未派单</span>";

                        if (hasPermission_powercancel) {
                            selectButton += "<li><a href='#' orderId='" + data.id + "' orderNo='" + data.orderNo + "' class='btn-link cancle'>销单</a></li>";
                        }
                        if (hasPermission_zhuanCreate) {
                            selectButton += "<li><a href='#' orderId='" + data.id + "' orderNo=" + data.orderNo + " class='btn-link zhuijia'>追加</a></li>";
                        }
                    } else if (data.status == 1) {
                        mainButton = "<a href='#'  orderId='" + data.id + "' orderNo='" + data.orderNo + "' class='btn btn-primary btn-xs callback'>收回</a>";
                        selectButton += "<li><a href='" + ctx + "/zhuanche/detail/" + data.id + "' class='btn-link'>查看</a></li>";
                        status = "<span class='btn btn-warning btn-xs'>已派单</span>";
                        if (hasPermission_powercancel) {
                            selectButton += "<li><a href='#' orderId='" + data.id + "' orderNo=" + data.orderNo + " class='btn-link cancle'>销单</a></li>";
                        }
                        if (hasPermission_zhuanCreate) {
                            selectButton += "<li><a href='#' orderId='" + data.id + "' orderNo=" + data.orderNo + " class='btn-link zhuijia'>追加</a></li>";
                        }
                    } else if (data.status == 2 || data.status == 3 || data.status == 4 || data.status == 5) {


                        mainButton = "<a href='" + ctx + "/zhuanche/detail/" + data.id + "' class='btn btn-primary btn-xs'>查看</a>";

                        if (hasPermission_zhuanCreate) {
                            selectButton += "<li><a href='#'  orderId=" + data.id + " orderNo=" + data.orderNo + "   class='btn-link zhuijia'>追加</a></li>";
                        }
                        if (hasPermission_orderComplete) {
                            selectButton += "<li><a href='javascript:;' orderId='" + data.id + "' class='btn-link wangong'>完工</a></li>";
                        }
                        selectButton += "<li><a href='#'  orderId=" + data.id + " orderNo=" + data.orderNo + " class='btn-link cancle'>销单</a></li>";
                        selectButton += "<li><a href='#'  orderId=" + data.id + " orderNo=" + data.orderNo + " class='btn-link callback'>收回</a></li>";
                        switch (data.status) {
                            case 2:
                                status = "<span class='btn btn-danger btn-xs'>已接单</span>";break;
                            case 3:
                                status = "<span class='btn btn-danger btn-xs'>开始等待</span>";break; case 4:
                                status = "<span class='btn btn-danger btn-xs'>执行中</span>";break; case 5:
                                status = "<span class='btn btn-default btn-xs'>已到达目的地</span>";break;
                        }
                    } else if (data.status == 6) {
                        if (hasPermission_zhuanCreate) {
                            mainButton = "<a href='#' orderId='" + data.id + "' orderNo=" + data.orderNo + " class='btn btn-primary btn-xs zhuijia'>追加</a>";
                            selectButton += "<li><a href='" + ctx + "/zhuanche/detail/" + data.id + "' class='btn-link'>查看</a></li>";
                            selectButton += ddbcString;
                        } else {
                            mainButton = "<li><a href='" + ctx + "/zhuanche/detail/" + data.id + "' class='btn-link'>查看</a></li>";
                        }
                        status = "<span class='btn btn-success btn-xs'>已完成</span>";
                    } else if (data.status == 7) {
                        if (hasPermission_zhuanCreate) {
                            mainButton = "<a href='#' orderId='" + data.id + "' orderNo=" + data.orderNo + " class='btn btn-primary btn-xs zhuijia'>追加</a>";
                            selectButton += "<li><a href='" + ctx + "/zhuanche/detail/" + data.id + "' class='btn-link'>查看</a></li>";
                            selectButton += ddbcString;
                        } else {
                            mainButton = "<li><a href='" + ctx + "/zhuanche/detail/" + data.id + "' class='btn-link'>查看</a></li>";
                        }

                        status = "<span class='btn btn-default btn-xs'>已销单</span>";
                    }
                    selectButton += "<li><a href='#' orderId='" + data.id + "' orderNo='" + data.orderNo + "' orderMemo='" + data.orderMemo + "' class='btn-link modifyCash'>备注</a></li>";
                    var allButton = "<div class='btn-group'>" +
                        mainButton +
                        "<button type='button' class='btn " + "btn-primary" + " btn-xs dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>" +
                        "<span class='caret'></span>" +
                        "<span class='sr-only'>Toggle Dropdown</span>" +
                        "</button>" +
                        "<ul class='dropdown-menu' role='menu'>" +
                        selectButton +
                        "</ul>" +
                        "</div>";
                    //所属公司
                    var companyNameTd = "";
                    if (mainCompany) {
                        companyNameTd = "<td>" + data.companyName + "</td>";
                    }
                    //加收费用
                    var guoluMoney;
                    var yuanchengMoney;
                    var otherMoney;
                    if (data.guoluMoney > 0) {
                        guoluMoney = "<font color='red'>" + data.guoluMoney.toFixed(1) + "</font>元";
                    } else {
                        guoluMoney = data.guoluMoney.toFixed(1) + "元";
                    }
                    if (data.yuanchengMoney > 0) {
                        yuanchengMoney = "<font color='red'>" + data.yuanchengMoney.toFixed(1) + "</font>元";
                    } else {
                        yuanchengMoney = data.yuanchengMoney.toFixed(1) + "元";
                    }
                    if (data.otherMoney > 0) {
                        otherMoney = "<font color='red'>" + data.otherMoney.toFixed(1) + "</font>元";
                    } else {
                        otherMoney = data.otherMoney.toFixed(1) + "元";
                    }


                    //结算方式
                    var payTypeDetails = "";
                    if ((data.status == 3 || data.status == 6) && null != data.payTypeDetails) {
                        if (data.payTypeDetails == "coupon_cash") {
                            payTypeDetails = "<td>优惠劵+现金</td>";
                        } else if (data.payTypeDetails == "cash") {
                            payTypeDetails = "现金";
                        } else if (data.payTypeDetails == "balance_cash") {
                            payTypeDetails = "余额+现金";
                        }
                    }
                    var memotr = data.memoStr;
                    if (null != memotr && memotr.length > 10) {
                        memotr = memotr.substring(0, 10) + "...";
                    }
                    var startAddress = data.startAddress;
                    if (null != startAddress && startAddress.length > 10) {
                        startAddress = startAddress.substring(0, 10) + "...";
                    } else if (startAddress == null) {
                        startAddress = "";
                    }
                    var endAddress = data.endAddress;
                    if (null != endAddress && endAddress.length > 10) {
                        endAddress = endAddress.substring(0, 10) + "...";
                    } else if (endAddress == null) {
                        endAddress = "";
                    }
                    var startAddressDetail = data.startAddressDetail;
                    if (startAddressDetail != null && startAddressDetail.length > 0) {
                        if (startAddressDetail.length > 14) {
                            startAddressDetail = "(" + startAddressDetail.substring(0, 14) + "...)";
                        } else {
                            startAddressDetail = "(" + startAddressDetail + ")";
                        }
                    } else {
                        startAddressDetail = "";
                    }
                    var endAddressDetail = data.endAddressDetail;
                    if (endAddressDetail != null && endAddressDetail.length > 0) {
                        if (endAddressDetail.length > 14) {
                            endAddressDetail = "(" + endAddressDetail.substring(0, 14) + "...)";
                        } else {
                            endAddressDetail = "(" + endAddressDetail + ")";
                        }
                    } else {
                        endAddressDetail = "";
                    }

                    var couponSpan = "";
                    if (data.couponId != null) {
                        couponSpan = "<span class='label status-td' style='color:#D4DDF1;background-color:#0063C3;'>券</span>";
                    }
                    if (data.bookStatus == 1) {
                        if (couponSpan != "") {
                            couponSpan = couponSpan + "&nbsp";
                        }
                        couponSpan = couponSpan + "<span class='label status-td' style='color:#D4DDF1;background-color:#F5931F;'>预</span>";
                    }
                    var addMoney = "<td>-</td>";
                    if (data.status == 6) {
                        addMoney = "<td>(过路费：" + guoluMoney + "，远程费：" + yuanchengMoney + "，其他费：" + otherMoney + ")</td>";
                    }
                    var realPay = "<td>-</td>";
                    if (data.status == 6) {
                        realPay = "<td>" + data.realPay.toFixed(1) + "元</td>";
                    }

                    var tiaojiaTd = "";
                    if (tiaojia) {
                        tiaojiaTd = "<td>" + (data.justKilometres == null ? "-，" : +data.justKilometres + "公里，") + (data.justMoney == null ? "-" : +data.justMoney + "元") + "</td>";
                    }

                    //结算方式
                    var realCashTD = "<td>-</td>";
                    if (data.status == 6  && null != data.preAndAfterPayType) {
                        realCashTD = "<td>" + (data.realPay != null ? data.realPay.toFixed(1) : 0) + "元（" + data.preAndAfterPayType + "）</td>";
                    }

                    // if(data.id == 337) {
                    //     debugger
                    // }
                    newcontent += "<tr class='grid-data tr-hui'  >" +
                        "<td>" + allButton + "</td>" +
                        "<td>" + status + "</td>" +
                        "<td><a href='" + ctx + "/zhuanche/detail/" + data.id + "' class='btn-link'>***" + data.orderNo.substring(8, data.orderNo.length) + "</a>" + couponSpan + "</td>" +
                        "<td>" + data.created + "</td>" +
                        "<td>" + data.channelName + "</td>" +
                        "<td>" + (data.createOrderName == null ? "" : data.createOrderName) + "</td>" +
                        "<td>" + data.passengerName + "</td>" +
                        "<td>" + data.passengerPhone + "</td>" +
                        "<td>" + data.showPhone + "</td>" +
                        "<td>" + data.serverTime + "</td>" +
                        "<td>" + startAddress + startAddressDetail + "</td>" +
                        "<td>" + endAddress + endAddressDetail + "</td>" +
                        realCashTD +
                        "<td>" + (data.budgetPay != null ? data.budgetPay.toFixed(1) : 0) + "元</td>" +
                        addMoney +
                        tiaojiaTd +
                        "<td>" + data.employName + "</td>" +
                        "<td>" + data.employPhone + "</td>" +
                        companyNameTd +
                        "<td>" + data.carTypeName + "</td>" +
                        "<td>" + data.serviceType + "</td>" +
                        "<td>" + data.carNumber + "</td>" +
                        "<td>" + (data.runtime != null ? data.runtime : 0) + "分钟</td>" +
                        "<td>" + (data.mileage != null ? data.mileage : 0) + "公里</td>" +
                        "<td>" + (data.midwayWait != null ? data.midwayWait : 0) + "分钟</td>" +
                        "<td>" + memotr + "</td>" +
                        "<td>" + data.cancelCause + "</td>" +
                        "<td>" + allButton + "</td>" +
                        "</tr>";
                });
            } else {
                $("#NoData").text("当前页面暂无记录 ");
            }

            if (!isappend) {
                $("#order_tbody .grid-data").remove();
            }
            $("#order_tbody").append(newcontent);
            $("#order_tbody .grid-data").each(function (index, element) {
                $(element).fadeIn(200 + (index * 35));
            });
            if (!hasShowPages) {
                if (!isappend) {
                    currentTotalElements = result.content.length;
                    pageLoading = true;
                } else {
                    if (currentTotalElements < totalElements) {
                        currentTotalElements += result.content.length;
                        pageLoading = true;
                    } else {
                        pageLoading = false;
                    }
                }
            }
            if (hasShowPages) {
                firstLoadPages = true;
                $(".pageshow li a").html("共" + totalElements + " 条数据");
                $(".pagedata").paging(totalElements, {
                    format: '[< ncnnn >]',
                    perpage: pagingLimit,
                    page: (offset / limit) + 1,
                    onSelect: function (page) {
                        limit = pagingLimit;
                        offset = (page - 1) * limit;
                        if (!firstLoadPages) {
                            initdata(false);
                        }
                        firstLoadPages = false;
                        return false;
                    },
                    onFormat: function (type) {
                        switch (type) {
                            case 'block': // n and c
                                if (!this.active)
                                    return '';
                                else if (this.value != this.page)
                                    return '<li><a href="#">' + this.value + '</a></li>';
                                return '<li class="active"><a href="#">' + this.value + '</a></li>';
                            case 'next': // >
                                return '<li><a href="#">&rsaquo;</a><li>';
                            case 'prev': // <
                                return '<li><a href="#">&lsaquo;</a><li>';
                            case 'first': // [
                                return '<li><a href="#">&laquo;</a><li>';
                            case 'last': // ]
                                return '<li><a href="#">&raquo;</a></li>';
                        }
                    }
                });
            } else {
                pageLoading = false;
                hasShowPages = true;
                $(".pageshow").show();
                $(".pagedata").show();
                $(".pageshow li a").html("共" + totalElements + " 条数据");
                $(".pagedata").paging(totalElements, {
                    format: '[< ncnnn >]',
                    perpage: pagingLimit,
                    onSelect: function (page) {
                        limit = pagingLimit;
                        offset = (page - 1) * limit;
                        if (!firstLoadPages) {
                            initdata(false);
                        }
                        firstLoadPages = false;
                        return false;
                    },
                    onFormat: function (type) {
                        switch (type) {
                            case 'block': // n and c
                                if (!this.active)
                                    return '';
                                else if (this.value != this.page)
                                    return '<li><a href="#">' + this.value + '</a></li>';
                                return '<li class="active"><a href="#">' + this.value + '</a></li>';
                            case 'next': // >
                                return '<li><a href="#">&rsaquo;</a><li>';
                            case 'prev': // <
                                return '<li><a href="#">&lsaquo;</a><li>';
                            case 'first': // [
                                return '<li><a href="#">&laquo;</a><li>';
                            case 'last': // ]
                                return '<li><a href="#">&raquo;</a></li>';
                        }
                    }
                });
            }
        }
    });
}

function showClientMaker(lng, lat) {
    var point = new BMap.Point(lng, lat);
    map = new BMap.Map("allmap");
    map.centerAndZoom(point, 14);
    map.enableScrollWheelZoom();
    var marker = new BMap.Marker(point);  // 创建标注
    map.addOverlay(marker);

    map.addControl(new BMap.MapTypeControl({
        anchor: BMAP_ANCHOR_TOP_RIGHT,
        mapTypes: [BMAP_NORMAL_MAP, BMAP_HYBRID_MAP]
    }));

    map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}));  //右上角，仅包含平移和缩放按钮

    var ctrl = new BMapLib.TrafficControl({
        showPanel: false //是否显示路况提示面板
    });
    map.addControl(ctrl);
    ctrl.setAnchor(BMAP_ANCHOR_TOP_LEFT);
}

function getDrivers(lng, lat) {
    var distance = $("#distance").val();
    var orderId = $("#paidanOrderId").val();
    $.get(ctx + '/driver/zhuanListDrivers', {
        'orderId': orderId,
        'lng': lng,
        'lat': lat,
        'distance': distance
    }, function (data) {
        if (data && data.length > 0) {
            $("#paidanDrivers").html('');
            $(data).each(function (i, driver) {
                var detailStatus = '';
                if (!driver.workCar) {
                    detailStatus = 'kongxian';
                } else {
                    detailStatus = 'workcar';
                }
                var htm = '<div id="driver_marker_' + driver.id + '" class="sj-mark driver_marker_class" style="position:absolute;z-index:9;">' +
                    '<div class="sj-mark-ma sjcolor-' + detailStatus + '"><span>' + driver.realname + '</span></div>' +
                    '<div class="sj-mark-rk rkcolor-' + detailStatus + '"></div>' +
                    '</div>';
                if (driver.workCar) {
                    htm = '<div id="driver_marker_' + driver.id + '" class="driver_workcar_marker_class" data-z-index="9998" style="position:absolute;z-index:9998;width:110px;">' +
                        '<div class="em-' + detailStatus + '-l"></div>' +
                        '<div class="em-' + detailStatus + '-con">' + driver.realname + '</div>' +
                        '<div class="em-' + detailStatus + '-r"></div>' +
                        '</div>';
                }
                var driverpoint = new BMap.Point(driver.longitude, driver.latitude);
                var drivermarker = new BMapLib.RichMarker(htm, driverpoint, {
                    "anchor": new BMap.Size(-62, -40),
                    "enableDragging": true
                });
                drivermarker.driverid = driver.id;
                drivermarker.driverstatus = driver.status;
                map.addOverlay(drivermarker);

                var usually = "";
                if (driver.usuallyEmploy) {
                    usually = "(荐)";
                }
                $("#paidanDrivers").append("<div class='modal-sj-bd' style='display:none;'><button type='button' class='paigeita' data-id='" + driver.id + "'>派给" + usually + "</button><span>" + driver.realname + "</span><span>" + driver.phone + "</span><span style='font-size:12px;'>" + driver.distanceStr + "</span></div>");
            });
            $(".paigeita").each(function (index, element) {
                $(element).parent().fadeIn((index + 1) * 300);
            });
        } else {
            $("#paidanDrivers").html(distance + "公里范围内暂无推荐服务人员，您可以扩大范围看看。");
        }
    });
}

function showLoading() {
    if ($('#loadblacklayer').length == 0) {
        var dw = $(".table").width();
        var dh = $(".table").height();
        var backlayer = "<div id='loadblacklayer'><div style='margin-top:" + (dh / 2) + "px;margin-left:" + (dw / 2) + "px;'><img src='" + ctx + "/assets/css/images/loading.gif' /></div></div>"
        $("#order_tbody").append(backlayer);
        $('#loadblacklayer').css({
            "z-index": "9",
            "background": "#000",
            "opacity": "0.5",
            "position": 'absolute',
            "top": 0,
            "width": dw,
            "height": dh
        });
    }
}

function hideLoading() {
    if ($('#loadblacklayer').length > 0) {
        $('#loadblacklayer').remove();
    }
}

Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1,                 //月份
        "d+": this.getDate(),                    //日
        "h+": this.getHours(),                   //小时
        "m+": this.getMinutes(),                 //分
        "s+": this.getSeconds(),                 //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds()             //毫秒
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
